package com.jjb.spider.common;

import io.netty.channel.ChannelHandlerContext;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class MemoryCache<K, V>{

    private final Map<K,V> datas ;

    public MemoryCache(int size) {
        datas = new ConcurrentHashMap(size);
    }

    public MemoryCache() {
        this(1000);
    }



    public void add(K key, V value) {
        this.datas.put(key, value);
    }

    public List<K> getKeys() {
        return datas.keySet().stream().collect(Collectors.toList());
    }

    public V get(K key) {
        return datas.get(key);
    }
}
